﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DataServer.SalaryCalculation
{
    public class DayBasedCalculation : CalculationStrategy
    {
        private int[] _months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        private int _month;
        private int _year;
        private int _soNgayNghi;
        private double _heSoLuongNgay = 200000;

        public double HeSoLuongNgay
        {
            get { return _heSoLuongNgay; }
            set { _heSoLuongNgay = value; }
        }

        public DayBasedCalculation(int month, int year, int soNgayNghi)
        {
            _month = month;
            _year = year;
            _soNgayNghi = soNgayNghi;
        }

        public override int computeSalary()
        {
            int soNgayTrongThang = getDaysOfMonth();
            double dLuong = (soNgayTrongThang - _soNgayNghi) * _heSoLuongNgay;
            int luong = Convert.ToInt32(dLuong);

            return luong;
        }

        private bool laNamNhuan()
        {
            if (_year % 400 == 0 ||
                (_year % 4 == 0 && _year % 100 != 0))
                return true;

            return false;
        }

        private int getDaysOfMonth()
        {
            int days = _months[_month-1];
            if (laNamNhuan() && _month == 2)
                days = 29;

            return days;
        }
    }
}